<?php

class BookmarkTDG_model extends CI_Model 
{
	private $TABLE = 'bookmark';

	public function __construct()
	{
		//$this->load->database();
	}

	public function findAll()
	{
		// return list of records matching criteria
		$query = $this->db->get( $this->TABLE  );
		return $query->result_array();
	}

	public function findById($id, $version)
	{
		$query = $this->db->get_where( $this->TABLE  , array('id' => $id) );

		// return a row matching criteria

	}

	public function insert($menuItemId, $userId, $restaurantId)
	{
		$data = array(
					   'menuItemId' => $menuItemId,
					   'userId' => $userId,
					   'restaurantId' => $restaurantId 
					 );

		$this->db->insert( $this->TABLE , $data); 

		// return id of the new entry

	}

	public function update($id, $version, $menuItemId, $userId, $restaurantId)
	{
		$data = array(
		               'menuItemId' => $menuItemId,
					   'userId' => $userId,					   
					   'restaurantId' => $restaurantId 
		            );

		$this->db->where( array('id' => $id, 'version' => $version) );
		$this->db->update( $this->TABLE , $data); 

		// return id of the updated entry entry
		
	}

	public function delete($id, $version)
	{
		$this->db->delete( $this->TABLE, array('id' => $id, 'version' => $version) ); 
		// return id of the deleted entry
		
	}

}